#include "gameover.h"
#include "ui_gameover.h"

GameOver::GameOver(QWidget *parent, QString newFilepath, bool highScore, int speed) :
//GameOver::GameOver(QWidget *parent, QString newFilepath, bool highScore) :
    QWidget(parent),
    ui(new Ui::GameOver)
{
    ui->setupUi(this);

    this->setGeometry(0, 0, 640, 640);
    //this->filepath = newFilepath;

    //Create Background Image
    QString background;
    if(highScore)
        background = newFilepath + "Images/highScore.png";
    else
        background = newFilepath + "Images/gameOver.png";
    bg = QImage(background);

    //Load Font
    QFontDatabase::addApplicationFont(newFilepath + "Qubix.ttf");
    buttonFont = new QFont("Qubix", 28, -1, false);
    ui->finalSpeed->setFont(*buttonFont);
    ui->finalSpeed->setText("<font color='#66A3FF'>Final Speed: </font><font color='#91D1FF'>" + QString::number(speed) + "</font>");

    //Create Buttons
    returnToMenu = new TextButton(this, "Return to Menu", "white", "#29E0FF");
    returnToMenu->setFont(*buttonFont);
    returnToMenu->setGeometry(156, 360, 327, 34);  //With font size of 28, width is ((letters + spaces/2) * 25 + 2)
    connect(returnToMenu, SIGNAL(clicked(QMouseEvent*)), this, SLOT(on_returnToMenu_clicked()));
    returnToMenu->show();
}

GameOver::~GameOver()
{
    delete ui;
}

void GameOver::on_returnToMenu_clicked()
{
    dynamic_cast<BaseWindow*>(this->parent())->showMainMenu();
    this->deleteLater();
}

void GameOver::paintEvent(QPaintEvent *event)
{
    //Create the painter
    QPainter painter(this);

    //Draw background image
    //painter.setBrush(QBrush(Qt::white, Qt::SolidPattern));
    QRect imageRect(0,0,this->width(), this->height());
    painter.drawImage(imageRect, bg);

    painter.end();
}
